package com.ssy.lingxi.order.handler.validator;

import com.ssy.lingxi.common.constant.order.OrderTypeEnum;
import com.ssy.lingxi.order.handler.annotation.SrmOrderTypeAnnotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Srm订单类型校验注解验证类
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-15
 */
public class SrmOrderTypeValidator implements ConstraintValidator<SrmOrderTypeAnnotation, Integer> {
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if(value == null) {
            return false;
        }

        return Stream.of(OrderTypeEnum.INQUIRY_TO_PURCHASE, OrderTypeEnum.QUERY_PRICE_CONTRACT, OrderTypeEnum.PRICE_COMPETITION_CONTRACT_PURCHASE, OrderTypeEnum.PURCHASE_CONTRACT_BIDDING).map(OrderTypeEnum::getCode).collect(Collectors.toList()).contains(value);
    }
}
